from rest_framework import serializers

from apps.goods.models import SPU, Brand, GoodsCategory


class SPUSerializer(serializers.ModelSerializer):
    """
           SPU序列化器
    """

    # 嵌套返回
    # 品牌外键
    brand = serializers.StringRelatedField(read_only=True)
    brand_id = serializers.IntegerField()

    # 提交时
    category1 = serializers.StringRelatedField(read_only=True)
    category2 = serializers.StringRelatedField(read_only=True)
    category3 = serializers.StringRelatedField(read_only=True)
    # 分类外键
    category1_id=serializers.IntegerField()
    category2_id=serializers.IntegerField()
    category3_id=serializers.IntegerField()

    class Meta:
        model = SPU
        fields = "__all__"


    ########品牌序列化器
class BrandSerializer(serializers.ModelSerializer):
    class Meta:
        model = Brand
        fields="__all__"


############### 商品分类序列化器
class GoodsCategorySerializer(serializers.ModelSerializer):

    class Meta:
        model=GoodsCategory
        fields="__all__"